package com.tinyseed.emcp.api.basicdata.repository;

import com.tinyseed.emcp.api.basicdata.domain.Monitor;
import com.tinyseed.emcp.api.basicdata.model.MonitorModel;
import com.tinyseed.emcp.api.dashboard.query.TreeQuickQuery;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/***
 * @ClassName: MonitorRepository
 * @Description: 监测点信息
 * @Auther: Harlan.Xiong
 * @Date: 2019-11-24 12:04
 * @version : V1.0
 */
public interface MonitorRepository extends JpaRepository<Monitor, Long>, JpaSpecificationExecutor<Monitor> {

    @Query(value = "select * from tb_monitor m where m.id = :id", nativeQuery = true)
    Monitor getById(@Param("id") Long id);

    List<Monitor> findByShopId(Long shopId);

    @Query(value = "select id,monitor_name,shop_id,equipment_type from tb_monitor ", nativeQuery = true)
    List<Map<String, Object>> findMonitors();

    @Query(value = "select new com.tinyseed.emcp.api.productionRule.query.MonitorModel(m.id,m.monitorName,m.shopId,m.equipmentType) from Monitor m ")
    List<MonitorModel> findAllMonitors();

    @Query(value = "select new com.tinyseed.emcp.api.dashboard.query.TreeQuickQuery(m.id,m.monitorName,m.shopId,m.equipmentType) from Monitor m ")
    List<TreeQuickQuery> queryMonitorTree();

    Long countByEquipmentTypeEquals(String equipmentType);

    int countByShopIdAndEquipmentType(Long shopId, String equipmentType);
}
